/**
* 头部菜单
*/ 
<template>
  <div class="navbar">
    <ham-burger id="hamburger-container" :is-active="collapsed" class="hamburger-container"
      @toggleClick="toggleSideBar" />

    <bread-crumb id="breadcrumb-container" class="breadcrumb-container" />

    <div class="right-menu">
      <header-language />

      <!-- 头像和下拉菜单 -->
      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
        <div class="avatar-wrapper">
          {{ username }} <i class="el-icon-caret-bottom"></i>
        </div>
        <el-dropdown-menu slot="dropdown">
          <router-link to="/user/setting">
            <el-dropdown-item>设置</el-dropdown-item>
          </router-link>
          <router-link to="/">
            <el-dropdown-item>首页</el-dropdown-item>
          </router-link>

          <el-dropdown-item divided @click.native="exit">
            <span style="display: block">退出</span>
          </el-dropdown-item>

        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>
<script>
import HamBurger from "./hamburger.vue";
import BreadCrumb from "./breadcrumb.vue";
import headerLanguage from "./headerLanguage.vue";
export default {
  name: "navcon",
  data() {
    return {
      username: "User",
      collapsed: true,
    };
  },
  components: { HamBurger, BreadCrumb, headerLanguage, },
  // 创建完毕状态(里面是操作)
  created() {
    this.username = this.$store.state.User.name;
  },
  methods: {
    exit() {
      this.$confirm("退出登录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // 清除一下session
          console.log('确定退出');
          this.$store.commit("User/LoginOut");
          this.$router.push({ path: "/" });
          this.$message({
            type: "success",
            message: "已退出登录!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    toggleSideBar() {
      this.collapsed = !this.collapsed;
      this.$emit("toggle", this.collapsed)
    },
    ToSearchPage() {
      this.$router.push({ path: '/user/search' })
    }
  },
};
</script>

<style scoped>
a {
  text-decoration: none;
}

.el-dropdown-menu--mini .el-dropdown-menu__item {
  line-height: 24px;
  padding: 0 10px;
  font-size: 12px;
}

.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
}

.hamburger-container {
  line-height: 46px;
  height: 100%;
  float: left;
  cursor: pointer;
  transition: background 0.6s;
  -webkit-tap-highlight-color: transparent;
}

.hamburger-container:hover {
  background: rgba(0, 0, 0, 0.025);
}

.breadcrumb-container {
  float: left;
}

.right-menu {
  float: right;
  height: 100%;
  line-height: 50px;
  padding-right: 20px;
  display: flex;
  justify-content: center;
  align-content: center;
  align-items: center;
}

.avatar-container {
  margin-right: 30px;
}

.avatar-wrapper {
  line-height: 50px;
  padding: 0 10px;
  position: relative;
}

.user-avatar {
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

.el-icon-caret-bottom {
  cursor: pointer;
  position: absolute;
  right: -20px;
  top: 25px;
  font-size: 12px;
}

.hover-effect {
  cursor: pointer;
  transition: background 0.6s;
}

.hover-effect:hover {
  background: rgba(0, 0, 0, 0.025);
}

.right-menu-item {
  display: inline-block;
  padding: 0 8px;
  height: 100%;
  font-size: 18px;
  color: #5a5e66;
  vertical-align: text-bottom;
}
</style>
